from pyecharts import options as opts
from pyecharts.charts import Bar
from pyecharts.commons.utils import JsCode
from pyecharts.globals import ThemeType
from pyecharts.faker import Faker
import csv


def make_bar_3():
    data = []
    with open('../csv/vilipixiv.csv', 'r', encoding='utf-8') as file:
        reader = csv.reader(file)
        for row in reader:
            data.append(row[0])
        data.pop(0)
    leng = []
    for i in data:
        leng.append(len(i))
    # print(data)
    # print(leng)
    c = Bar()
    c.add_xaxis(data)
    c.add_yaxis("起名长度", leng)
    c.set_global_opts(
            xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=-15)),
            title_opts=opts.TitleOpts(title="作品起名长度的探究"),
            datazoom_opts=[opts.DataZoomOpts(range_start=0, range_end=100, orient="horizontal")]
        )
    c.render("../html/作品名称长度条形图.html")

    return c


if __name__ == "__main__":
    make_bar_3()
